﻿Imports PTIC_Util

''' <summary>
''' Classe représentant un fichier physique
''' </summary>
''' <remarks></remarks>
<Serializable()> Public Class Cla_NomFichier
    Inherits BaseNotifyPropertyChangeComponentModel

#Region "Constructeur"
    ''' <summary>
    ''' Constructeur
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub New(ByVal nomComplet As String)
        Me.NomComplet = nomComplet
    End Sub
    ''' <summary>
    ''' Constructeur
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub New()
        NomComplet = ""
    End Sub
#End Region

#Region "Nom Complet"
    ''' <summary>
    ''' Nom complet du fichier d'encours (chemin + nom du fichier + extension)
    ''' </summary>
    ''' <remarks></remarks>
    Public Property NomComplet As String
        Get
            Return _NomComplet
        End Get
        Set(ByVal value As String)
            OnPropertyChanging("NomComplet")
            Dim e As New PropertyChangeEventArgs(Of String)(nomComplet, value)
            If e.IsValide Then RaiseEvent NomCompletChanging(Me, e)
            If e.IsValide Then
                _NomComplet = e.NewValue
                'Mise à jour des autres propriétés (en lecture seule) de la classe
                onNomCompletChanged(Me, e)
                OnPropertyChanged("NomComplet")
                RaiseEvent NomCompletChanged(Me, e)
            End If
        End Set
    End Property
    Private _NomComplet As String
    Public Event NomCompletChanging As PropertyChangeEventHandler(Of String)
    Public Event NomCompletChanged As PropertyChangeEventHandler(Of String)
    Private Sub onNomCompletChanged(ByVal Sender As Object, ByVal e As PropertyChangeEventArgs(Of String))
        If e.NewValue <> "" Then
            Me.Ext = IO.Path.GetExtension(NomComplet).Replace(".", "").Trim()
            'Me.Ext = Microsoft.VisualBasic.Right(NomComplet, _
            ' Len(NomComplet) - InStr(NomComplet, ".", CompareMethod.Text))
            Me.NomRepertoire = IO.Path.GetDirectoryName(NomComplet).Trim()
            'Me.NomRepertoire = Microsoft.VisualBasic.Left(NomComplet, _
            '     InStrRev(NomComplet, "\") - 1)
            Me.NomRelatif = IO.Path.GetFileName(NomComplet).Trim()
            'Me.NomRelatif = Microsoft.VisualBasic.Right(NomComplet, _
            ' Len(NomComplet) - InStrRev(NomComplet, "\"))
            Me.NomSansExt = IO.Path.GetFileNameWithoutExtension(NomComplet).Trim()
            'Me.NomSansExt = Microsoft.VisualBasic.Left(_NomRelatif, _
            '    InStrRev(_NomRelatif, ".") - 1)

            Dim o = 1
        Else
            Me.Ext = ""
            Me.NomRepertoire = ""
            Me.NomRelatif = ""
            Me.NomSansExt = ""
        End If
    End Sub
    Public Sub GenererNomCompletChanged()
        OnPropertyChanged("NomComplet")
        Dim e As New PropertyChangeEventArgs(Of String)(NomComplet, NomComplet)
        e.IsValide = True
        RaiseEvent NomCompletChanged(Me, e)
    End Sub
#End Region

#Region "Nom Relatif"
    ''' <summary>
    ''' Nom relatif : nom du fichier à l'intérieur du répertoire (nom fichier + extension)
    ''' </summary>
    ''' <remarks></remarks>
    Public Property NomRelatif As String
        Get
            Return _NomRelatif
        End Get
        Private Set(ByVal value As String)
            OnPropertyChanging("NomRelatif")
            If _NomRelatif <> value Then
                _NomRelatif = value
                OnPropertyChanged("NomRelatif")
            End If
        End Set
    End Property
    Private _NomRelatif As String
#End Region

#Region "Nom Répertoire"
    ''' <summary>
    ''' Nom complet du répertoire contenant le fichier
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Property NomRepertoire As String
        Get
            Return _NomRepertoire
        End Get
        Private Set(ByVal value As String)
            OnPropertyChanging("NomRepertoire")
            If _NomRepertoire <> value Then
                _NomRepertoire = value
                OnPropertyChanged("NomRepertoire")
            End If
        End Set
    End Property
    Private _NomRepertoire As String
#End Region

#Region "Exension"
    ''' <summary>
    ''' Extension du fichier
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Property Ext As String
        Get
            Return _Ext
        End Get
        Private Set(ByVal value As String)
            OnPropertyChanging("Ext")
            If _Ext <> value Then
                _Ext = value
                OnPropertyChanged("Ext")
            End If
        End Set
    End Property
    Private _Ext As String
#End Region

#Region "Nom fichier sans extension"
    ''' <summary>
    ''' Nom relatif hors extension (nom fichier seul)
    ''' </summary>
    ''' <remarks></remarks>
    Public Property NomSansExt As String
        Get
            Return _NomSansExt
        End Get
        Private Set(ByVal value As String)
            OnPropertyChanging("NomSansExt")
            If _NomSansExt <> value Then
                _NomSansExt = value
                OnPropertyChanged("NomSansExt")
            End If
        End Set
    End Property
    Private _NomSansExt As String
#End Region

End Class
